]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
appDisplay: Bring back drag overshoot region
authorGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>
Tue, 9 Aug 2022 22:39:41 +0000 (19:39 -0300)
committerMarge Bot <marge-bot@gnome.org>
Wed, 10 Aug 2022 15:16:36 +0000 (15:16 +0000)
This is a region where, if hovered while dragging, immediately goes
to the previous or next page. This behavior was lost during the
transition to the new app grid layout manager.

Bring back the drag overshoot region.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2335>

js/ui/appDisplay.js

index 9ede9a6900b9c3998f857144b66ce7e0fa8c55eb..92ed05b72f15f0362dab493ed9dcc09fb5c8b0f3 100644 (file)
@@ -43,6 +43,7 @@ const PAGE_PREVIEW_ANIMATION_TIME = 150;
 const PAGE_INDICATOR_FADE_TIME = 200;
 const PAGE_PREVIEW_RATIO = 0.20;
 
+const OVERSHOOT_THRESHOLD = 20;
 const OVERSHOOT_TIMEOUT = 300;
 
 const DELAYED_MOVE_TIMEOUT = 200;
@@ -843,6 +844,23 @@ var BaseAppView = GObject.registerClass({
         this._overshootTimeoutId = 0;
     }
 
+    _dragWithinOvershootRegion(dragEvent) {
+        const rtl = this.get_text_direction() === Clutter.TextDirection.RTL;
+        const {x, y, targetActor: indicator} = dragEvent;
+        const [indicatorX, indicatorY] = indicator.get_transformed_position();
+        const [indicatorWidth, indicatorHeight] = indicator.get_transformed_size();
+
+        let overshootX = indicatorX;
+        if (indicator === this._nextPageIndicator || rtl)
+            overshootX += indicatorWidth - OVERSHOOT_THRESHOLD;
+
+        const overshootBox = new Clutter.ActorBox();
+        overshootBox.set_origin(overshootX, indicatorY);
+        overshootBox.set_size(OVERSHOOT_THRESHOLD, indicatorHeight);
+
+        return overshootBox.contains(x, y);
+    }
+
     _handleDragOvershoot(dragEvent) {
         // Already animating
         if (this._adjustment.get_transition('value') !== null)
@@ -868,6 +886,13 @@ var BaseAppView = GObject.registerClass({
         if (targetPage < 0 || targetPage >= this._grid.nPages)
             return; // don't go beyond first/last page
 
+        // If dragging over the drag overshoot threshold region, immediately
+        // switch pages
+        if (this._dragWithinOvershootRegion(dragEvent)) {
+            this._resetOvershoot();
+            this.goToPage(targetPage);
+        }
+
         this._overshootTimeoutId =
             GLib.timeout_add(GLib.PRIORITY_DEFAULT, OVERSHOOT_TIMEOUT, () => {
                 this._resetOvershoot();